{extend name="base" /}
{block name="css"}
{/block}
{block name="body"}
<!-- 主要内容 开始 -->
<div class="weui-tab__bd-item">
    <header class="weui-navBar weui-navBar-fixed">
        <a href="javascript:history.go(-1);" class="weui-navBar-item">
            <i class="icon iconfont icon-fanhui"></i>
        </a>
        <div class="weui-center">
            <span class="weui-center-title">我的地址</span>
        </div>
        <a href="javascript:;" class="weui-navBar-item">
            <i class="icon iconfont"></i>
        </a>
    </header>
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" value="{$data.consignee|default=''}" id="name" placeholder="请输入收货人姓名">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">手机号</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="tel" value="{$data.mobile|default=''}"  maxlength="11" id="mobile" pattern="[0-9]*" placeholder="请输入手机号">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="date" class="weui-label">收货地址</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" id="city"  type="text" value="{$data.province|default='北京'} {$data.city|default='北京市'} {$data.district|default='东城区'}">
            </div>
        </div>
        <div class="weui-cells__title">详细地址</div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
              <textarea class="weui-textarea" placeholder="请输入详细地址" id="addr" rows="3">{$data.address|default=''}</textarea>
            </div>
        </div>
        <div class="weui-btn-area">
          <button class="weui-btn weui-btn_primary btn">保存</button>
        </div>
    </div>
</div>
<!-- 主要内容 结束 -->
{/block}
{block name="js"}
{js href="__LIB__/js/city-picker.js" /}
<script type="text/javascript">
$(function(){
    $("#city").cityPicker({
        title: "选择目的地"
    });
    //保存收货地址
    $('.btn').click(function() {
        var name = $('#name').val();
        var mobile = $('#mobile').val();
        var city = $('#city').val();
        var addr = $('#addr').val();
        var type = '{$Request.param.type}';
        if(!mobile || !/1[3|4|5|6|7|8|9]\d{9}/.test(mobile)) $.toptip('请输入手机号');
        else if(!name) $.toptip('请输入收货人姓名');
        else if(!city) $.toptip('请选择收货地址');
        else if(!addr) $.toptip('请输入详细地址');
        else $.post('', {name: name,mobile:mobile,city:city,addr:addr,id:type}, function(res) {
            if (res.code === 1) {
                $.toast(res.msg,'text');
                setTimeout(function(){
                  location.href = '/address.html';
                },1000);
            } else {
                $.toptip(res.msg);
            }
        });
    });
});
</script>
{/block}